
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>菜单/用户信息管理</h1>
	<ol class="breadcrumb">
		<li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>
				首页</a></li>
		<li><a href="#">用户管理</a></li>
		<li class="active">菜单/用户信息管理</li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<div class="box box-primary">
				<div class="box-body">
					<div class="row">
						<div class="col-sm-2">
							<div class="dataTables_length">
								<label>
									<select class="form-control input-sm pageSize" style="width:auto;">
										<option>10</option>
										<option>20</option>
										<option>30</option>
										<option>30</option>
										<option>40</option>
									</select>
									记录/页
								</label>
							</div>
						</div>
						<div class="col-sm-10">
							<div class="dataTables_filter" id="searchDiv">
								<input type="search" placeholder="请输入用户名" title="用户名" name="username"
									   class="form-control">
								<input type="search" placeholder="请输入海康用户名" title="海康用户名" name="hIKUsername"
									   class="form-control">
								<select  type="search"  title="用户类型" name="userType" class="form-control userType"></select>
								<input  type="text" placeholder="起始时间" name="startTime" readonly title="起始时间"
										class='form-control date' value=''>
								<input  type="text" placeholder="结束时间" name="endTime" readonly title="结束时间"
										class='form-control date' value=''>

								<div class="btn-group">
									<button type="button" class="btn btn-primary" data-btn-type="search">查询</button>
								</div>
								<div class="btn-group">
									<button type="button" class="btn btn-default" data-btn-type="add">新增</button>
								</div>
							</div>
						</div>
					</div>


					<table id="check_table" class="table table-bordered table-striped table-hover" style="margin-bottom:20px;">
						<thead>
						<tr>
							<th name="id" style="display:none;">id</th>
							<th name="username">用户名</th>
							<th name="phone">手机号</th>
							<th name="userType">用户类型</th>
							<th name="hIKUsername">海康用户名</th>
							<th name="createUsername">负责人</th>
							<th name="createDateTime">更新时间</th>
							<th name="">功能选项</th>
						</tr>
						</thead>
						<tbody></tbody>
					</table>
					<div class="paging"></div>
				</div>
			</div>
		</div>
	</div>
	</div>
</section>

<script>
	$(function() {
        new Date().datepicker();
        loadSelectByClassSync("${basePath}/manager/user/getUserRoleList",null,"userType","--请选择用户类型--","userType","role");
        //$("[name='userType']").loadSelect2("","请选择用户类型",2);
        var table=initTable("${basePath}/manager/user/getUserList",
            $(".content #searchDiv"),
            $(".content table"),
            $(".content .pageSize"),
            $(".content .paging"));
        var param={
            htmlUrl:"${basePath}/function/manager/user/userForm",
            getEntityUrl:"${basePath}/manager/user/getUserInfo",
            updateEntityUrl:"${basePath}/manager/user/updateUserInfo",
            deleteEntityUrl:" ${basePath}/manager/user/deleteUser",
            editTitle:"编辑用户信息",
            addTitle:"添加用户",
            addButton:$("[data-btn-type='add']"),
            table:$(".content table"),
            getEntityBefore:function (value) {
                if(value.createUserId!=null){
                    var option=$("<option></option>");
                    option.attr("value",value.createUserId);
                    option.text(value.createUsername);
                    $("#userForm [name='createUserId']").empty().append(option);
				}
            },
            getEntityCallback:function (value) {
                $('#userForm [name="sensorGroups"]').val("");
                $('#userForm [name="monitors"]').val("");
                $("#userForm .monitor .body table tbody").empty();
                $("#userForm .sensor table tbody").empty();
                var sensorGroups="";
                for(var i=0;i<value.sensorGroups.length;i++){
                    var id=value.sensorGroups[i].id;
                    var name=value.sensorGroups[i].sensorGroupName;
                    var tr = $("<tr></tr>");
                    var buttonTd = $("<td><button type='button' class='btn btn-primary btn-sm'>删除</button></td>");
                    var nameTd = $("<td>" + name + "</td>");
                    tr.attr("id",id).append(buttonTd).append(nameTd);
                    $("#userForm .sensor .body table tbody").append(tr);
                    sensorGroups+=","+id;
				}
				var monitors="";
                for(var i=0;i<value.monitors.length;i++){
                    var id=value.monitors[i].id;
                    var name=value.monitors[i].probeName;
                    var tr = $("<tr></tr>");
                    var buttonTd = $("<td><button type='button' class='btn btn-primary btn-sm'>删除</button></td>");
                    var nameTd = $("<td>" + name + "</td>");
                    tr.attr("id",id).append(buttonTd).append(nameTd);
                    $("#userForm .monitor .body table tbody").append(tr);
                    monitors+=","+id;
                }
                $('#userForm [name="sensorGroups"]').val(sensorGroups);
                $('#userForm [name="monitors"]').val(monitors);
            },
            addCallback:function () {
                $('#userForm [name="sensorGroups"]').val("");
                $('#userForm [name="monitors"]').val("");
                $("#userForm .monitor .body table tbody").empty();
                $("#userForm .sensor table tbody").empty();
            }
		};
        EditEntity(param,table.search);

    });
</script>
